//
//  ReleaseHallViewController.m
//  Logistics
//
//  Created by hy002 on 2018/1/15.
//  Copyright © 2018年 HUYU. All rights reserved.
//

#import "ReleaseHallViewController.h"
#import "GoodsAddressModel.h"
#import "CloseGoodsAddressViewController.h"
#import "TruckTypeModel.h"
#import "CarInfoViewController.h"

static NSString *cellPath = @"ReleaseCell";
@interface ReleaseHallViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIScrollViewDelegate,UIPickerViewDelegate,UIPickerViewDataSource,UITextViewDelegate>
{
    UIPickerView *pickTypeView;
    UITextView *conView;
    UIView *cliseTimeView;
    UIView *grayView;
}
@property (nonatomic,strong)UIView *TypeView;
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSArray *titAry;
@property (nonatomic, strong)NSArray *imgAry;
@property (nonatomic, strong)NSArray *allTagAry;
@property (nonatomic, strong)NSString *volume;
@property (nonatomic, strong)NSString *weight;
@property (nonatomic, strong)NSString *price;
@property (nonatomic, strong)NSString *pladerStr;
@property (nonatomic, strong)NSArray *typeAry;
@property (nonatomic, strong)NSString *infoName;
@property (nonatomic, strong)NSString *startAddress;
@property (nonatomic, strong)NSString *stopAddress;
@property (nonatomic, strong)NSString *hallType;
@property (nonatomic, strong)NSString *carInfo;
@property (nonatomic, strong)NSString *timeStr;
@property (nonatomic, strong)NSString *cargoTagid;
@property (nonatomic, strong)NSString *cargoid;
@property (nonatomic, strong)NSString *truckTypeId;
@property (nonatomic, strong)NSString *shipmentid;
@property (nonatomic, strong)NSString *destinationid;
@property (nonatomic, strong)NSString *shipmentDay;
@property (nonatomic, strong)NSString *shipmentTime;
@property (nonatomic, strong)NSString *lengthStr;
@property (nonatomic, strong)NSString *baffle;
@property (nonatomic, strong)NSArray *timeTitAry;
@property (nonatomic, strong)NSArray *timesAry;
@property (nonatomic, assign)NSInteger dayType;
@property (nonatomic, assign)NSInteger timeType;

@property (nonatomic, assign)NSInteger tagType;
@property (nonatomic, assign)NSInteger TruckType;
@property (nonatomic, assign)NSInteger lenthType;
@property (nonatomic, assign)NSInteger baffType;

@property (nonatomic, assign)BOOL isEdit;
@property (nonatomic, assign)BOOL isGx;
@property (nonatomic, assign)BOOL isHall;
@property (nonatomic, assign)BOOL iscloseTime;
@property (nonatomic, strong)UILabel *strLengthLab;
@property (nonatomic, strong)NSString *contectLength;


@end

@implementation ReleaseHallViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self dataInit];
    [self creatUI];
    [self creatTimeView];
    [self requestCargoType];
    [self requestCargoTagList];
}

- (void)dataInit
{
    _infoName = @"";
    _volume = @"";
    _weight = @"";
    _price = @"";
    _startAddress = @"";
    _stopAddress = @"";
    _hallType = @"";
    _carInfo = @"";
    _timeStr = @"";
    _cargoTagid = @"";
    _cargoid = @"";
    _truckTypeId = @"";
    _shipmentid = @"";
    _destinationid = @"";
    _shipmentDay = @"";
    _shipmentTime = @"";
    _lengthStr = @"";
    _baffle = @"";
    _pladerStr = @"备注：";
    _contectLength = @"0/45";
    _dayType = 0;
    _timeType = 0;
    _tagType = 0;
    _TruckType = 0;
    _lenthType = 0;
    _baffType = 0;
    _titAry = @[@[@"信息类型",@"装货地址",@"卸货地址"],@[@"货物类型",@"体积",@"重量",],@[@"车辆信息",@"发货时间",@"运费",@""]];
    _imgAry = @[@[@"lb_icon011",@"lb_icon012",@"lb_icon13"],@[@"lb_icon14",@"lb_icon15",@"lb_icon16",],@[@"lb_icon17",@"lb_icon18",@"lb_icon19",@""]];
    _timeTitAry = @[@"今天",@"明天",@"后天",@"大后天"];
    _timesAry = @[@"00:00--06:00",@"06:00--12:00",@"12:00--18:00",@"18:00--24:00"];
}

- (void)creatUI
{
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"发布信息";
    self.view.backgroundColor = BacksColor;
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(15*displaywidth, 15*displaywidth, SCREEN_WIDTH-30*displaywidth, SCREEN_HEIGHT-STA_NAV_HEIGHT-95*displaywidth-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.layer.cornerRadius = 10;
    _tableview.layer.masksToBounds = YES;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableview];
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-STA_NAV_HEIGHT-SCREER_HeiX-65*displaywidth, SCREEN_WIDTH, 65*displaywidth+SCREER_HeiX)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(soureBtnAction) Title:@"立即发布" Font:16.0];
    soureBtn.backgroundColor = RGB(255, 153, 0);
    [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    soureBtn.layer.cornerRadius = 5;
    soureBtn.layer.masksToBounds = YES;
    [bottomView addSubview:soureBtn];
}

- (void)creatTimeView
{
    cliseTimeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    cliseTimeView.backgroundColor = RGBA(0, 0, 0, 0.6);
    [sharedDelegate.window addSubview:cliseTimeView];
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cliseTimeViewPressed)];
    [cliseTimeView addGestureRecognizer:tap1];
    grayView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-200*displaywidth-SCREER_HeiX, SCREEN_WIDTH, 200*displaywidth+SCREER_HeiX)];
    grayView.backgroundColor = BacksColor;
    [cliseTimeView addSubview:grayView];
    UIView *whiteV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45*displaywidth)];
    whiteV.backgroundColor = [UIColor whiteColor];
    [grayView addSubview:whiteV];
    CGFloat W = (SCREEN_WIDTH-60*displaywidth)/4;
    for (int i = 0; i < _timeTitAry.count; i++)
    {
        UIButton *dayBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth+(W+10*displaywidth)*i, 10*displaywidth, W, 35*displaywidth) ImageName:nil Target:self Action:@selector(closeDay:) Title:_timeTitAry[i] Font:15.0];
        dayBtn.backgroundColor = [UIColor clearColor];
        [dayBtn setTitleColor:RGB(187, 187, 187) forState:UIControlStateNormal];
        if (i == _dayType)
        {
            dayBtn.backgroundColor = BacksColor;
            [dayBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
        }
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:dayBtn.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(4, 4)];
        CAShapeLayer *layer = [[CAShapeLayer alloc]init];
        layer.frame = dayBtn.bounds;
        layer.path = maskPath.CGPath;
        dayBtn.layer.mask = layer;
        dayBtn.tag = 10+i;
        [grayView addSubview:dayBtn];
        
    }
    for (int i = 0; i < _timesAry.count; i++)
    {
        UIButton *timeBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH/2*(i%2), 80*displaywidth+(i/2)*60*displaywidth, SCREEN_WIDTH/2, 30*displaywidth) ImageName:nil Target:self Action:@selector(closeTime:) Title:_timesAry[i] Font:15.0];
        timeBtn.backgroundColor = [UIColor clearColor];
        [timeBtn setTitleColor:RGB(187, 187, 187) forState:UIControlStateNormal];
        timeBtn.tag = 30+i;
        [grayView addSubview:timeBtn];
        
    }
    cliseTimeView.hidden = YES;
}

- (void)cliseTimeViewPressed
{
    cliseTimeView.hidden = YES;

}

- (void)closeDay:(UIButton *)btn
{
    _dayType = btn.tag-10;
    if (_iscloseTime)
    {
        _timeStr = [NSString stringWithFormat:@"%@%@",_timeTitAry[_dayType],_timesAry[_timeType]];
        [_tableview reloadData];
    }
    for (id v in grayView.subviews)
    {
        if ([v isKindOfClass:[UIButton class]])
        {
            UIButton *button = (UIButton *)v;
            if (button.tag < 30)
            {
                button.backgroundColor = [UIColor clearColor];
                [button setTitleColor:RGB(187, 187, 187) forState:UIControlStateNormal];
            }
        }
    }
    btn.backgroundColor = BacksColor;
    [btn setTitleColor:ThemeColor forState:UIControlStateNormal];

}

- (void)closeTime:(UIButton *)btn
{
    _iscloseTime = YES;
    _timeType = btn.tag-30;
    _timeStr = [NSString stringWithFormat:@"%@%@",_timeTitAry[_dayType],_timesAry[_timeType]];
    NSArray *newTimeAry = @[@"0-6点",@"6-12点",@"12-18点",@"18-24点"];
    _shipmentDay = _timeTitAry[_dayType];
    _shipmentTime = newTimeAry[_timeType];
    cliseTimeView.hidden = YES;
    [_tableview reloadData];
    for (id v in grayView.subviews)
    {
        if ([v isKindOfClass:[UIButton class]])
        {
            UIButton *button = (UIButton *)v;
            if (button.tag >= 30)
            {
                [button setTitleColor:RGB(187, 187, 187) forState:UIControlStateNormal];
            }
        }
    }
    [btn setTitleColor:YellowColor forState:UIControlStateNormal];
    
}

- (void)companyAction
{
    if (!self.TypeView)
    {
        self.TypeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT)];
        _TypeView.backgroundColor = RGBA(0, 0, 0, 0.6);
        [self.view addSubview:_TypeView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bottomViewPressed)];
        [_TypeView addGestureRecognizer:tap];
        pickTypeView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-250*displayheight-STA_NAV_HEIGHT, SCREEN_WIDTH, 250*displayheight)];
        pickTypeView.backgroundColor = [UIColor whiteColor];
        pickTypeView.delegate = self;
        pickTypeView.dataSource = self;
        [_TypeView addSubview:pickTypeView];
        UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-280*displayheight-STA_NAV_HEIGHT, SCREEN_WIDTH, 30*displayheight)];
        whiteView.backgroundColor = [UIColor whiteColor];
        [_TypeView addSubview:whiteView];
        UIButton *cancelBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, 10*displayheight, 40*displaywidth, 20*displayheight) ImageName:nil Target:self Action:@selector(bottomViewPressed) Title:@"取消" Font:13.0];
        cancelBtn.backgroundColor = ThemeColor;
        [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        cancelBtn.layer.cornerRadius = 3;
        cancelBtn.layer.masksToBounds = YES;
        [whiteView addSubview:cancelBtn];
        
        UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH- 55*displaywidth, 10*displayheight, 40*displaywidth, 20*displayheight) ImageName:nil Target:self Action:@selector(soureAction) Title:@"确定" Font:13.0];
        soureBtn.backgroundColor = ThemeColor;
        [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        soureBtn.layer.cornerRadius = 3;
        soureBtn.layer.masksToBounds = YES;
        [whiteView addSubview:soureBtn];
        
    }
    _TypeView.hidden = NO;
    
    
}

- (void)soureAction
{
    if (_isHall)
    {
        NSInteger selectRow = [pickTypeView selectedRowInComponent:0];
        GoodsAddressModel *model = _typeAry[selectRow];
        _hallType = model.name;
        _cargoid = s_str(model.ID);
        [self bottomViewPressed];
        [_tableview reloadData];
    }
    else
    {
        NSInteger selectRow = [pickTypeView selectedRowInComponent:0];
        TruckTypeModel *model = _allTagAry[selectRow];
        _infoName = model.name;
        if ([model.isEdit integerValue] == 1)
        {
            _isEdit = YES;
        }
        else
        {
            _isEdit = NO;
        }
        _cargoTagid = s_str(model.ID);
        [self bottomViewPressed];
        [_tableview reloadData];
    }
    
}


- (void)bottomViewPressed
{
    _TypeView.hidden = YES;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

//指定每个表盘上有几行数据
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (_isHall)
    {
        return _typeAry.count;
    }
    return _allTagAry.count;
}

#pragma mark UIPickerView Delegate Method 代理方法

//指定每行如何展示数据（此处和tableview类似）
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (_isHall)
    {
        GoodsAddressModel *model = _typeAry[row];
        return model.name;
    }
    else
    {
        TruckTypeModel *model = _allTagAry[row];
        return model.name;
    }
    
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"%ld------%ld",component,row);
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *numAry = _titAry[section];
    if (!_isEdit && section == 1)
    {
        return 0;
    }
    return numAry.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if ((!_isEdit && indexPath.section != 1) || _isEdit)
    {
        if (!(indexPath.section == 0 && indexPath.row == 0))
        {
            UIView *lineAview = [[UIView alloc] initWithFrame:CGRectMake(50*displaywidth, 0, SCREEN_WIDTH-95*displaywidth, 1)];
            lineAview.backgroundColor = LinesColor;
            [cell.contentView addSubview:lineAview];
        }
        if (indexPath.section == 2 && indexPath.row == 3)
        {
            NSString *imgStr = @"gouxuan1";
            if (_isGx)
            {
                imgStr = @"gouxuan2";
            }
            UIButton *gouXuan = [ZCControl createButtonWithFrame:CGRectMake(50*displaywidth, 5*displaywidth, 150*displaywidth, 25*displaywidth) ImageName:imgStr Target:self Action:@selector(gouxuanAction:) Title:@" 加急" Font:13.0];
            [gouXuan setTitleColor:YellowColor forState:UIControlStateNormal];
            gouXuan.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            gouXuan.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            [cell.contentView addSubview:gouXuan];
            UITextView *contentAView = [[UITextView alloc] initWithFrame:CGRectMake(15*displaywidth, 40*displaywidth, SCREEN_WIDTH-60*displaywidth, 145*displaywidth)];
            contentAView.delegate = self;
            contentAView.text = _pladerStr;
            contentAView.textColor = RGB(179, 179, 179);
            if (![_pladerStr isEqualToString:@"备注："])
            {
                contentAView.textColor = BlaTitColor;
            }
            contentAView.backgroundColor = BacksColor;
            contentAView.layer.cornerRadius = 10;
            contentAView.layer.masksToBounds = YES;
            [cell.contentView addSubview:contentAView];
            conView = contentAView;
            UILabel *lenthLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 185*displaywidth, SCREEN_WIDTH-65*displaywidth, 25*displaywidth) Font:10.0 Text:_contectLength Color:RGB(179, 179, 179)];
            lenthLab.textAlignment = NSTextAlignmentRight;
            [cell.contentView addSubview:lenthLab];
            _strLengthLab = lenthLab;
            return cell;
        }
        NSInteger index = indexPath.row;
        NSArray *imageArray = _imgAry[indexPath.section];
        cell.imageView.image = IMAGE(imageArray[index]);
        cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
        NSArray *titleArray = _titAry[indexPath.section];
        cell.textLabel.text = titleArray[index];
        cell.textLabel.font = NormalFontWithSize(17.0+fontScale);
        cell.textLabel.textColor = BlaTitColor;
        NSArray *isShuRuAry = @[@[@"0",@"0",@"0"],@[@"0",@"1",@"1",],@[@"0",@"0",@"1",@""]];
        NSArray *isTextAry = isShuRuAry[indexPath.section];
        NSString *isTextStr = isTextAry[index];
        if ([isTextStr isEqualToString:@"0"])
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            NSArray *rightNameAry = @[@[_infoName,_startAddress,_stopAddress],@[_hallType,@"1",@"1",],@[_carInfo,_timeStr,@"1",@""]];
            NSArray *labAry = rightNameAry[indexPath.section];
            UILabel *rightLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-230*displaywidth, 5*displaywidth, 170*displaywidth, 40*displaywidth) Font:14.0 Text:labAry[index] Color:BlaTitColor];
            rightLab.textAlignment = NSTextAlignmentRight;
            [cell.contentView addSubview:rightLab];
        }
        if (indexPath.section != 0)
        {
            if ([isTextStr isEqualToString:@"1"])
            {
                NSArray *textAry = @[@[@"",@"",@""],@[@"",_volume,_weight,],@[@"",@"",_price,@""]];
                NSArray *nameAry = textAry[indexPath.section];
                UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(SCREEN_WIDTH-230*displaywidth, 5*displaywidth, 185*displaywidth, 40*displaywidth) placeholder:@"" passWord:NO leftImageView:nil rightImageView:nil Font:14.0];
                textfield.textColor = BlaTitColor;
                textfield.delegate = self;
                textfield.tag = (indexPath.section+1)*100+index;
                textfield.text = nameAry[index];
                textfield.keyboardType = UIKeyboardTypeDecimalPad;
                if (indexPath.section == 1 && index == 1)
                {
                    textfield.placeholder = @"/立方";
                }
                if (indexPath.section == 1 && index == 2)
                {
                    textfield.placeholder = @"/吨";
                }
                textfield.textAlignment = NSTextAlignmentRight;
                [cell.contentView addSubview:textfield];
            }
        }
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = indexPath.section;
    NSInteger index = indexPath.row;
    if (section == 0)
    {
        if (index == 1 || index == 2)
        {
            WEAKSELF;
            CloseGoodsAddressViewController *vc = [[CloseGoodsAddressViewController alloc] init];
            vc.areaType = index;
            vc.isPush = YES;
            vc.closeBlock = ^(NSString *name, NSInteger index)
            {
                NSArray *nameAry = [name componentsSeparatedByString:@","];
                if (nameAry.count == 2)
                {
                    if (index == 1)
                    {
                        _startAddress = nameAry[0];
                        _shipmentid = nameAry[1];
                    }
                    else
                    {
                        _stopAddress = nameAry[0];
                        _destinationid = nameAry[1];
                    }
                }
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [weakSelf.tableview reloadData];
                });
            };
            [self.navigationController pushViewController:vc animated:YES];
        }
        else
        {
            _isHall = NO;
            [self companyAction];
            [pickTypeView reloadAllComponents];
        }
        
    }
    else if (section == 1)
    {
        if (index == 0)
        {
            _isHall = YES;
            [self companyAction];
            [pickTypeView reloadAllComponents];
        }
    }
    else if (section == 2)
    {
        if (index == 0)
        {
            WEAKSELF;
            //信息筛选
            CarInfoViewController *vc = [[CarInfoViewController alloc] init];
            vc.TruckType = _TruckType;
            vc.lenthType = _lenthType;
            vc.baffType = _baffType;
            vc.closeBlock = ^(NSString *truckId, NSString *lenthStr, NSString *baffStr,NSInteger truck,NSInteger len,NSInteger baf)
            {
                NSArray *truAry = [truckId componentsSeparatedByString:@","];
                if (truAry.count == 2)
                {
                    weakSelf.lengthStr = lenthStr;
                    weakSelf.truckTypeId = truAry[1];
                    weakSelf.baffle = baffStr;
                    weakSelf.TruckType = truck;
                    weakSelf.lenthType = len;
                    weakSelf.baffType = baf;
                    NSString *lenStr = truAry[0];
                    if (![lenthStr isEqualToString:@""])
                    {
                        lenStr = [lenStr stringByAppendingString:[NSString stringWithFormat:@"/%@米",lenthStr]];
                    }
                    if ([baffStr integerValue] == 1)
                    {
                        lenStr = [lenStr stringByAppendingString:@"/需尾板"];
                    }
                    if ([baffStr integerValue] == 0)
                    {
                        lenStr = [lenStr stringByAppendingString:@"无需尾板"];
                    }
                    weakSelf.carInfo = lenStr;
                    [weakSelf.tableview reloadData];
                }
                
            };
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (index == 1)
        {
            cliseTimeView.hidden = NO;
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!_isEdit && indexPath.section == 1)
    {
        return 0;
    }
    if (indexPath.section == 2 &&indexPath.row == 3)
    {
        return 200*displaywidth;
    }
    return 50*displaywidth;
}

- (void)gouxuanAction:(UIButton *)btn
{
    _isGx = !_isGx;
    NSString *imgStr = @"gouxuan1";
    if (_isGx)
    {
        imgStr = @"gouxuan2";
    }
    [btn setImage:IMAGE(imgStr) forState:UIControlStateNormal];
    [btn setTitle:@" 加急" forState:UIControlStateNormal];
}


//提交
- (void)soureBtnAction
{
    [self.view endEditing:YES];
    NSArray *nameARRAY = @[_infoName,_startAddress,_stopAddress,_carInfo,_timeStr,_price];
    NSArray *tostAry = @[@"请选择信息类型",@"请选择装货地址",@"请选择卸货地址",@"请选择车辆信息",@"请选择发货时间",@"请输入运费"];
    for (int i = 0; i < nameARRAY.count; i++)
    {
        if ([nameARRAY[i] isEqualToString:@""])
        {
            [LTools showMBProgressWithText:tostAry[i] addToView:self.view];
            return;
        }
    }
    if (_isEdit)
    {
        if ([_hallType isEqualToString:@""])
        {
            [LTools showMBProgressWithText:@"请选择货物类型" addToView:self.view];
            return;
        }
        if ([_volume isEqualToString:@""] && [_weight isEqualToString:@""])
        {
            [LTools showMBProgressWithText:@"货物体积和质量必选填一项" addToView:self.view];
            return;
        }
    }
    NSString *contStr = _pladerStr;
    if ([_pladerStr isEqualToString:@"备注："])
    {
        contStr = @"";
    }
    NSString *isJi = @"0";
    if (_isGx)
    {
        isJi = @"1";
    }
    WEAKSELF;
    NSDictionary *dic = @{@"cargoTag.id":_cargoTagid,
                          @"shipment.id":_shipmentid,
                          @"destination.id":_destinationid,
                          @"shipmentDay":_shipmentDay,
                          @"shipmentTime":_shipmentTime,
                          @"truckTypeId":_truckTypeId,
                          @"length":_lengthStr,
                          @"baffle":_baffle,
                          @"cargoTypeId":_cargoid,
                          @"weight":_weight,
                          @"volume":_volume,
                          @"price":_price,
                          @"remark":contStr,
                          @"ji":isJi};
    [HYBaseHandler requestWithTheFormUrl:SERVER_cargoSave Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            [LTools showMBProgressWithText:@"发布成功" addToView:sharedDelegate.window];
            [self.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {

    }];
}

//类型
- (void)requestCargoType
{
    WEAKSELF;
    NSDictionary *dic = @{@"size":@"999"};
    [HYBaseHandler requestWithTheFormUrl:SERVER_cargoType Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            _typeAry = [GoodsAddressModel mj_objectArrayWithKeyValuesArray:obj[@"data"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [pickTypeView reloadAllComponents];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

//信息类型
- (void)requestCargoTagList
{
    WEAKSELF;
    [HYBaseHandler requestWithTheFormUrl:SERVER_cargoTagList Parmers:nil Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             _allTagAry = [TruckTypeModel mj_objectArrayWithKeyValuesArray:obj[@"data"]];
             dispatch_async(dispatch_get_main_queue(), ^{
                 
                 [weakSelf.tableview reloadData];
             });
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.tag == 302)
    {
        _price = textField.text;
        
    }
    else if (textField.tag == 201)
    {
        _volume = textField.text;
    }
    else if (textField.tag == 202)
    {
        _weight = textField.text;
    }
    _tableview.frame = CGRectMake(15*displaywidth, 15*displaywidth, SCREEN_WIDTH-30*displaywidth, SCREEN_HEIGHT-STA_NAV_HEIGHT-95*displaywidth-SCREER_HeiX);

}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField.tag == 302)
    {
        _tableview.frame = CGRectMake(15*displaywidth, -150, SCREEN_WIDTH-30*displaywidth, SCREEN_HEIGHT-STA_NAV_HEIGHT-95*displaywidth-SCREER_HeiX);
        
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.view endEditing:YES];
    return indexPath;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.view endEditing:YES];
    
}

//开始编辑
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    textView.textColor = BlaTitColor;
    if ([textView.text isEqualToString:@"备注："])
    {
        textView.text = @"";
    }
    if (_isEdit)
    {
        [_tableview setContentOffset:CGPointMake(0, 120*displaywidth) animated:YES];
    }
    _tableview.frame = CGRectMake(15*displaywidth, -160, SCREEN_WIDTH-30*displaywidth, SCREEN_HEIGHT-STA_NAV_HEIGHT-95*displaywidth-SCREER_HeiX);
    
}



//结束编辑
- (void)textViewDidEndEditing:(UITextView *)textView
{
    _strLengthLab.text = [NSString stringWithFormat:@"%ld/45",textView.text.length];
    _contectLength = _strLengthLab.text;
    _pladerStr = textView.text;
    if ([textView.text isEqualToString:@""])
    {
        textView.text = @"备注：";
        _pladerStr = @"备注：";
        textView.textColor = RGB(179, 179, 179);
    }
   
    _tableview.frame = CGRectMake(15*displaywidth, 15*displaywidth, SCREEN_WIDTH-30*displaywidth, SCREEN_HEIGHT-STA_NAV_HEIGHT-95*displaywidth-SCREER_HeiX);
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    _strLengthLab.text = [NSString stringWithFormat:@"%ld/45",textView.text.length];
    _contectLength = _strLengthLab.text;
    NSInteger  charactersAfterChange = textView.text.length + text.length - range.length;
    if (charactersAfterChange >= 45)
    {
        return NO;
    }
    //删除
    if ([text isEqualToString:@""]) {
        return YES;
    }
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        //在这里做你响应return键的代码
        [self.view endEditing:YES];
        return NO; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
    }
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
